package com.open.capacity.tenant.config;


import lombok.extern.slf4j.Slf4j;
import org.flywaydb.core.Flyway;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;

/**
 * flyway加载数据源完成迁移
 * @program: open-capacity-platform
 * @author: GuoGaoJu
 * @create: 2023-03-22
 **/
@Component
@Slf4j
@RefreshScope
public class DataSourceConfiguration {

    @Value("${spring.flyway.url}")
    private String url;

    @Value("${spring.flyway.username}")
    private String username;

    @Value("${spring.flyway.password}")
    private String password;

    /**
     * flyway进行数据脚本迁移--创建schema
     * @Param schema 新建schema名称
     */
    public void migrate(String schema){
        Flyway.configure().dataSource(url,username,password).schemas(schema).load().migrate();
    }

}
